// stores/experimentStore.js
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useExperimentStore = defineStore(
  'experimentStore',
  () => {
    // 使用 ref 定义响应式状态
    const collectedExperiments = ref({
      experimentName: '',
      teamName: '',
      testMethod: ''
    })

    // 定义动作
    const setCollectedExperiments = (data) => {
      collectedExperiments.value = { ...collectedExperiments.value, ...data }
    }

    const saveCurrentData = async () => {
      // 模拟保存数据的逻辑
      return new Promise((resolve) => {
        setTimeout(() => {
          console.log('数据已保存:', collectedExperiments.value)
          resolve()
        }, 1000)
      })
    }

    return {
      collectedExperiments,
      setCollectedExperiments,
      saveCurrentData
    }
  },
  {
    persist: {
      enabled: true,
      strategies: [
        {
          key: 'experimentStore',
          storage: localStorage
        }
      ]
    }
  }
)
